/** 
 * @package: BrickCAD
 * @className: BrickImagePanel.java
 * @package: default
 * @author: Sean O'Brien, Jack, Lester Tam, Erik Telstad
 * @date_created: November 29, 2009
 * @last_motified: November 29, 2009
 * 
 * a class representing a component to display a view of the brick 
 * 
 */

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

import javax.swing.JPanel;


public class BrickImagePanel extends JPanel {
	
	private static final long serialVersionUID = 1L;
	private double brickX, brickY;
	private Rectangle2D.Double brick;
	private Color brickColor, outlineColor;

	/**
	 * a constructor for a new JPanel that will hold the image within the
	 * view frame
	 * 
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 */
	public BrickImagePanel(int frameWidth, int frameHeight, double brickWidth, double brickHeight) {
	   
		setPreferredSize(new Dimension(frameWidth, frameHeight));
		//System.out.print("Expecting width = 300 Width = " + frameWidth);
		//System.out.println(" Expecting height = 300 Height = " + frameHeight);
		brickX = getX() + frameWidth/2 - (brickWidth/2);
		brickY = getY() + (frameHeight+10)/2 - (brickHeight/2);
	    
		brick = new Rectangle2D.Double(brickX, brickY, brickWidth, brickHeight);
		brickColor = Color.RED;
		outlineColor = Color.BLACK;
	}
	   
	/**
	 * a method to get the height of the image
	 * 
	 * @return height height of brick image, relative to perspective
	 */
	public double getBrickHeight() {
		return brick.height;		   
	}

	/**
	 * a method to get the width of the image
	 * 
	 * @return width width of brick image, relative to perspective
	 */
	public double getBrickWidth() {
		return brick.width;		   
	}

	/**
	 * a method to set the height of the image
	 * 
	 * @param h value for new height of image
	 */
	public void setBrickHeight(double h) {
		brick.height = h;		   
	}

	/**
	 * a method to set the width of the image
	 * 
	 * @param w value for new width of image
	 */
	public void setBrickWidth(double w) {
	   brick.width = w;		   
	}
	   
	/**
	 * a method to set the location of the image
	 * UNUSED/UNTESTED FOR NOW
	 * 
	 * @param x x-coordinate of starting point(upper left) for the image frame
	 * @param y y-coordinate of starting point(upper left) for the image frame
	 * @param ctrX x-coordinate of center point of the image frame
	 * @param ctrY y-coordinate of center point of the image frame
	 */
	public void setLocation(double x, double y, double ctrX, double ctrY) {
	   brick.setFrameFromCenter(x, y, ctrX, ctrY);
	   repaint();
	}

	/* (non-Javadoc)
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 * override paint
	 */
	@Override
	public void paintComponent(Graphics gc) {
		super.paintComponent(gc);
	    Graphics2D gc2d = (Graphics2D)gc;
	    draw(gc2d);
	}
	   
	/**
	 * a method to draw the image
	 * @param gc Graphics context used to draw the image
	 */
	public void draw(Graphics2D gc) {
	   Color oldColor = gc.getColor();
	   gc.setColor(brickColor);
	   gc.fill(brick);
	   gc.setColor(outlineColor);
	   gc.draw(brick);
	   gc.setColor(oldColor);		  
	}

}
